﻿using System.Linq;
using TestsModel.Data;

namespace TestsModel
{
    public class TestChecker
    {
        public static int Check(TestData nativeTestData, TestData externalTestData)
        {
            var finalResult = 0;

            //Check Check Tests
            if (nativeTestData.CheckTestQuestions.Count == externalTestData.CheckTestQuestions.Count)
            {
                for (int i = 0; i < nativeTestData.CheckTestQuestions.Count; i++)
                {
                    finalResult += CheckCheckTest(nativeTestData.CheckTestQuestions[i],
                        externalTestData.CheckTestQuestions[i]);
                }
            }

            //Check Radio Tests
            if (nativeTestData.RadioTestQuestions.Count == externalTestData.RadioTestQuestions.Count)
            {
                for (int i = 0; i < nativeTestData.RadioTestQuestions.Count; i++)
                {
                    finalResult += CheckRadioTest(nativeTestData.RadioTestQuestions[i],
                        externalTestData.RadioTestQuestions[i]);
                }
            }

            //Check Input Tests
            if (nativeTestData.InputTestQuestions.Count == externalTestData.InputTestQuestions.Count)
            {
                for (int i = 0; i < nativeTestData.InputTestQuestions.Count; i++)
                {
                    finalResult += CheckInputTest(nativeTestData.InputTestQuestions[i],
                        externalTestData.InputTestQuestions[i]);
                }
            }

            // Check Match Tests
            if (nativeTestData.MatchTestQuestions.Count == externalTestData.MatchTestQuestions.Count)
            {
                for (int i = 0; i < nativeTestData.MatchTestQuestions.Count; i++)
                {
                    finalResult += CheckMatchTest(nativeTestData.MatchTestQuestions[i],
                        externalTestData.MatchTestQuestions[i]);
                }
            }

            if (nativeTestData.FillTestQuestions.Count == externalTestData.FillTestQuestions.Count)
            {
                for (int i = 0; i < nativeTestData.FillTestQuestions.Count; i++)
                {
                    finalResult += CheckFillTest(nativeTestData.FillTestQuestions[i],
                        externalTestData.FillTestQuestions[i]);
                }
            }

            return finalResult;
        }

        public static int CheckCheckTest(CheckTest nativeCheckTest, CheckTest externalCheckTest)
        {
            return nativeCheckTest.Check(externalCheckTest.Statements);
        }
        public static int CheckRadioTest(RadioTest nativeRadioTest, RadioTest externalRadioTest)
        {
            return nativeRadioTest.Check(externalRadioTest.Answer);
        }
        public static int CheckInputTest(InputTest nativeInputTest, InputTest externalInputTest)
        {
            return nativeInputTest.Check(externalInputTest.Answer);
        }
        public static int CheckMatchTest(MatchTest nativeMatchTest, MatchTest externalMatchTest)
        {
            return nativeMatchTest.Check(externalMatchTest.LeftStatements.Select(x => x.Item2).ToList());
        }
        public static int CheckFillTest(FillTest nativeFillTest, FillTest externalFillTest)
        {
            return nativeFillTest.Check(externalFillTest.ParseAnswers());
        }
    }
}